﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text.RegularExpressions;

/// <summary>
/// Summary description for Formatting
/// </summary>
public class Formatting
{
    public static string ConvertUrlsToHyperlinks(string S)
    {
         S = S.Replace("\n", " <br/>");
         return Regex.Replace(S, "(\bhttp://[^ ]+\b)", "<a target='_blank' href='$0'>$0</a>");
    }

    public static string FormatDKPhone(string num)
    {
        string results = String.Empty;
        if (!String.IsNullOrEmpty(num))
        {
            //first we must remove all non numeric characters
            num = num.Replace(" ", "").Replace("+", "").Trim();
            results = string.Empty;
            string formatPattern = @"(\d{2})(\d{2})(\d{2})(\d{2})";
            results = Regex.Replace(num, formatPattern, "$1 $2 $3 $4");
        }
        //now return the formatted phone number
        if (!String.IsNullOrEmpty(results))
        {
            return results;
        }
        else
        {
            return "";
        }
    }
}
